// Copyright 2020 Poofee (https://github.com/Poofee)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
/*****************************************************************************
 *                                                                           *
 *  File:    relay3d.h                                                       *
 *                                                                           *
 *****************************************************************************
 *                                                                           *
 *  Authors: Poofee                                                          *
 *  Email:   poofee@qq.com                                                   *
 *  Address: https://github.com/Poofee                                       *
 *  Date:    2020年07月15日                                                   *
 *                                                                           *
 *****************************************************************************/
#ifndef RELAY3D_H
#define RELAY3D_H

#include "relay.h"

enum MotionType {
	STRAIGHTMOTION,/** 直线运动 **/
	ROTATEMOTION,/** 旋转运动 **/
};

typedef struct _MOTION_INFO {
    double v[3]; /** 单位向量 **/
	double p[3]; /** 轴上点 **/
	MotionType type; /** 0:parallel shift;1:rotate **/
} MOTION_INFO;

class Relay3D : public Relay {
public:
	Relay3D();

	virtual void remesh(int timestep);
	void findAir();

    void makeJ();
    void makeJCircularCoil(CElement* ele, CMaterial* mat);
    void makeJRectangularCoil(CElement* ele, CMaterial* mat);

    void allocateMemory();
    void setBoundary();

    void MagnetoStatic3DNR();
    void MagnetoDynamics3DNR();
    void MagnetoStatic3DATLM();
    void MagnetoStatic3DQMTLM();
    void MagnetoDynamics3DATLM();

	void writeVtkFile(char *fname);
	void writeVtkFileNoAir(char * fname);
    void writeCurrentDensityField(char *fname);
    void writeNodalForceDensityField(char *fname);

    double calcMagForce(int index, FORCEMETHOD method);
    double nodalForceMST(int index);
    double nodalForceVW(int index);
    double calcMagTorque(int index, FORCEMETHOD method);
	void updateResults();

	virtual void StaticInitial();
	virtual void TransientInitial();
	virtual void StaticAnalysis();
	virtual void TransientAnalysis();
public:
    MOTION_INFO motion;
};

#endif // RELAY3D_H
